<?php
/**
 * Created by JetBrains PhpStorm.
 * User: cgp
 * Date: 13-7-26
 * Time: 上午8:59
 * 日志类
 */
namespace pft\Log;
class Log {
    /**
     * @const ALIPAY_LOG_PATH 支付宝日志
     */
    const ALIPAY_LOG_PATH = '/var/www/html/new/d/logs/ali_log.txt';
    /**
     * @const UNIPAY_LOG_PATH 银联日志
     */
    const UNIPAY_LOG_PATH = '/var/www/html/new/d/logs/uni_log.txt';
    /**
     * @const DEBUG_LOG_PATH 调试日志
     */
    const DEBUG_LOG_PATH = '/var/www/html/new/d/logs/debug_log.txt';
    /**
     * @const ORDER_LOG_PATH 支付后订单处理日志
     */
    const ORDER_LOG_PATH = '/var/www/html/new/d/logs/order_log.txt';
    /**
     * @const ERROR_LOG_PATH 错误日志
     */
    const ERROR_LOG_PATH = '/var/www/html/new/d/logs/error_log.txt';
    /**
     * @const OCRS_LOG_PATH 取消订单重发短信日志记录
     */
    const OCRS_LOG_PATH = '/var/www/html/new/d/logs/ocrs_log.txt';

    /**
     * @const SYSOPT_LOG_PATH 大后台产品操作日志
     */
    const SYSOPT_LOG_PATH = '/var/www/html/new/d/logs/sysopt_log.txt';//大后台产品操作日志
    /**
     * @const 开发调试日志
     */
    const DEV_LOG_PATH = '/var/www/html/new/d/logs/dev.log';
    /**
     * @const 环迅支付回传参数日志
     */
    const IPS_LOG_PATH = '/var/www/html/new/d/module/zax/ips_pay/log/log.txt';
    /**
     * 文件格式日志记录
     *
     * @param $word 记录信息
     * @param string $filepath 日志文件路径
     */
    static public function writeLog($word, $filepath=self::ERROR_LOG_PATH) {
        $maxsize  =  10485760;//1024*1024*10;
        if(file_exists($filepath)){
            $filesize = filesize($filepath);
            $filetype = end(explode(".",$filepath)); //获取文件后缀名
            $filename = substr($filepath,0,strpos($filepath,'.'));
            if($filesize>$maxsize) {
                rename($filepath, $filename.'_'.date('Ymd').'.'.$filetype);
            }
        }
        $fp = fopen($filepath,"a");
        flock($fp, LOCK_EX) ;
        fwrite($fp,"\n".$word);
        flock($fp, LOCK_UN);
        fclose($fp);
    }
}